Customized cover letter

In today's competitive job market, standing out from the crowd is crucial, and a personalized cover letter can be the key to catching the eye of your potential employer. Recognizing this, we introduce you to the creation of a Customized Cover Letter Generator in this section. This innovative tool is designed to help you write cover letters that not only highlight your unique skills and experiences but also tailor them to the specific job and the company you’re applying for. By inputting intended company, position, job description, and your resume, the generator will provide you with a cover letter that is both professional and personalized, ensuring that your application makes a memorable impression. Let's dive into how to create such a tool.

Alt text

Following the approach of the previous code, we will now reconfigure the Gradio interface and develop a function specifically for generating the cover letter, with particular emphasis on the prompt construction. The complete code snippet follows:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  1. # Import necessary packages
  2. from ibm_watsonx_ai import Credentials
  3. from ibm_watsonx_ai import APIClient
  4. from ibm_watsonx_ai.foundation_models import Model, ModelInference
  5. from ibm_watsonx_ai.foundation_models.schema import TextChatParameters
  6. from ibm_watsonx_ai.metanames import GenTextParamsMetaNames
  7. import gradio as gr
  8. # Model and project settings
  9. model_id = "meta-llama/llama-3-2-11b-vision-instruct" # Directly specifying the LLAMA3 model
  10. # Set credentials to use the model
  11. credentials = Credentials(
  12. url = "https://us-south.ml.cloud.ibm.com",
  13. )
  14. # Generation parameters
  15. params = TextChatParameters(
  16. temperature=0.7,
  17. max_tokens=512
  18. )
  19. project_id = "skills-network"
  20. # Initialize the model
  21. model = ModelInference(
  22. model_id=model_id,
  23. credentials=credentials,
  24. project_id=project_id,
  25. params=params
  26. )
  27. # Function to generate a customized cover letter
  28. def generate_cover_letter(company_name, position_name, job_description, resume_content):
  29. # Craft the prompt for the model to generate a cover letter
  30. prompt = f"Generate a customized cover letter using the company name: {company_name}, the position applied for: {position_name}, and the job description: {job_description}. Ensure the cover letter highlights my qualifications and experience as detailed in the resume content: {resume_content}. Adapt the content carefully to avoid including experiences not present in my resume but mentioned in the job description. The goal is to emphasize the alignment between my existing skills and the requirements of the role."
  31. messages = [
  32. {
  33. "role": "user",
  34. "content": [
  35. {
  36. "type": "text",
  37. "text": prompt
  38. },
  39. ]
  40. }
  41. ]
  42. # Generate a response using the model with parameters
  43. generated_response = model.chat(messages=messages)
  44. # Extract and return the generated text
  45. cover_letter = generated_response['choices'][0]['message']['content']
  46. return cover_letter
  47. # Create Gradio interface for the cover letter generation application
  48. cover_letter_app = gr.Interface(
  49. fn=generate_cover_letter,
  50. flagging_mode="never", # Deactivate the flag function in gradio as it is not needed.
  51. inputs=[
  52. gr.Textbox(label="Company Name", placeholder="Enter the name of the company..."),
  53. gr.Textbox(label="Position Name", placeholder="Enter the name of the position..."),
  54. gr.Textbox(label="Job Description Information", placeholder="Paste the job description here...", lines=10),
  55. gr.Textbox(label="Resume Content", placeholder="Paste your resume content here...", lines=10),
  56. ],
  57. outputs=gr.Textbox(label="Customized Cover Letter"),
  58. title="Customized Cover Letter Generator",
  59. description="Generate a customized cover letter by entering the company name, position name, job description and your resume."
  60. )
  61. # Launch the application
  62. cover_letter_app.launch()

To run the code:

  1. Create a new python file named cover_letter.py.
  2. Input the code provided above.
  3. In the terminal, run
  1. 1
  1. python3.11 cover_letter.py
  1. Launch the application by clicking the following button.

If the application launches successfully, it should appear as follows:

Alt text

You are now ready to test this application by entering the required information as prompted.

(To terminate the script, press Ctrl+C in the terminal and close the appliction window.)

Exercise

If you prefer to input specific technical skills keywords rather than the entire job description, could you modify the code to replace the Job Description Information input with a Job Skills Keywords input?

Click here for the answer You need to revise the code as following and adjust the prompt as necessary.
  1. 1
  2. 2
  1. #gr.Textbox(label="Job Description Information", placeholder="Paste the job description here...", lines=10),
  2. gr.Textbox(label="Job Skills Keywords", placeholder="Paste the job required skills keywords here...", lines=2),